var loginBtn = document.querySelector('header .member > div')
loginBtn.onclick = function(){
    document.querySelector('section.login').style.visibility = 'visible'

}
var chaBtn = document.querySelector('section.login i.icon-close')
chaBtn.onclick = function(){
    document.querySelector('section.login').style.visibility = 'hidden'
}

var lanBtn = document.querySelector('section.login div.menu')
lanBtn.onmousedown = function(evt){
    var olde = evt || window.event 
    document.onmousemove = function(evt){
        var e = evt || window.event 
        var left = e.clientX - olde.offsetX
        var top = e.clientY - olde.offsetY
        var logind = document.querySelector('section.login .item')
        logind.style.left = left +'px'
        logind.style.top = top +'px'
    }
}
    document.onmouseup = function() {
        document.onmousemove = null
}



// 倒计时
var num = 60
var djsBtn = document.querySelector('section.login .captcha')
djsBtn.onclick = function(){
    // 行为验证码
    var xwbtn = document.querySelector('section.captcha')
    xwbtn.style.visibility = 'visible'
    // 关闭行为验证码
    document.querySelector('section.captcha i.icon-close').onclick =function(){
        xwbtn.style.visibility = 'hidden'
    }

    // 移动位置
    var tzbtn = document.querySelector('section.captcha div.btn')
    tzbtn.onmousedown = function(){
        document.onmousemove = function(evt){
            var e = evt || window.event
            var left = e.clientX - (xwbtn.offsetLeft-xwbtn.offsetWidth/2-tzbtn.offsetWidth/2)
            tzbtn.style.left = left + 'px'
            document.querySelector('section.captcha div.check img:nth-of-type(2)').style.left = left + 'px'
        }
        document.onmouseup = function(){
            document.onmousemove = null
            var num = parseInt(tzbtn.style.left)
            if(num>=260&&num<=265){
                xwbtn.style.visibility = 'hidden'

                // 倒计时
                djsBtn.innerText = num+'秒后重发'
                djsBtn.disabled =true
                t=setInterval(function(){
                  if(num<=1){
                  clearInterval(t)
                  djsBtn.innerText = '重新发送'
                  // t = null
                  num=60
                  djsBtn.disabled = false
                  return
                  }
                 num--
                 djsBtn.innerText = num+'秒后重发'
                },1000)
                // 倒计时结束
            }else{
                tzbtn.style.left = 0
            document.querySelector('section.captcha div.check img:nth-of-type(2)').style.left = 0
            }
        }
    } 
    return



    
}

// 表单验证
var dzbtn = document.querySelector('section.login .submit')
dzbtn.onclick = function(){
    var num= 0
    var mobileobj = document.querySelector('.mobile')
    var pwdobj = document.querySelector('.password')
    if(mobileobj.value==''||mobileobj.value.length !== 11|| ! Number(mobileobj.value)){
        document.querySelector('section.login .form > p:nth-of-type(3)').innerText='输入格式有误'
    }else{
        num++
        document.querySelector('section.login .form > p:nth-of-type(3)').innerText=''
    }
    if(pwdobj.value==''||pwdobj.value.length !== 4|| ! Number(pwdobj.value)){
        document.querySelector('section.login .form > p:nth-of-type(4)').innerText='输入格式有误'
    }else{
        num++
        document.querySelector('section.login .form > p:nth-of-type(4)').innerText=''
    }
    if(num==2) {
        alert('登陆成功')
        // document.querySelector('section.login').style.visibility='visible'
    }
}